package com.lj.queue.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lj.common_web.annotation.ResponseResultVo;
import com.lj.common_web.utils.ServletUtil;
import com.lj.queue.param.DelayQueueMessagePageParam;
import com.lj.queue.param.DelayQueueMessageSaveParam;
import com.lj.queue.param.DelayQueueMessageUpdateParam;
import com.lj.queue.result.DelayQueueMessageInfoResult;
import com.lj.queue.result.DelayQueueMessagePageResult;
import com.lj.queue.service.DelayQueueMessageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 延迟队列消息表 前端控制器
 * </p>
 *
 * @author lj
 * @since 2025-07-21 16:55:02
 */
@RestController
@RequestMapping("/queue/delay_queue_message")
@ResponseResultVo
@Tag(name = "延迟队列消息表 管理")
public class DelayQueueMessageController {

    @Resource
    private DelayQueueMessageService delayQueueMessageService;

    @GetMapping("/page")
    @SaCheckPermission("queue:delay_queue_message:list")
    @Operation(summary = "延迟队列消息表 分页查询")
    public IPage<DelayQueueMessagePageResult> page(@ParameterObject DelayQueueMessagePageParam param) {
        return delayQueueMessageService.page(param);
    }

    @GetMapping("/info/{id}")
    @SaCheckPermission("queue:delay_queue_message:info")
    @Operation(summary = "延迟队列消息表 信息")
    public DelayQueueMessageInfoResult info(@PathVariable("id") @Parameter(name = "id", description = "延迟队列消息表 id") Long id) {
        if (id == null) {
            return null;
        }
        return delayQueueMessageService.info(id);
    }

    @PostMapping("/save")
    @SaCheckPermission("queue:delay_queue_message:save")
    @Operation(summary = "延迟队列消息表 新增")
    public void save(@RequestBody @Validated DelayQueueMessageSaveParam param) {
        delayQueueMessageService.save(param);
    }

    @PostMapping("/update")
    @SaCheckPermission("queue:delay_queue_message:update")
    @Operation(summary = "延迟队列消息表 更新")
    public void update(@RequestBody @Validated DelayQueueMessageUpdateParam param) {
        delayQueueMessageService.update(param);
    }

    @PostMapping("/delete")
    @SaCheckPermission("queue:delay_queue_message:delete")
    @Operation(summary = "延迟队列消息表 删除")
    public void delete(@RequestBody List<Long> ids) {
        delayQueueMessageService.delete(ids);
    }

    @PostMapping("/import/excel")
    @SaCheckPermission("queue:delay_queue_message:import")
    @Operation(summary = "延迟队列消息表 excel导入")
    public void importExcel(@Parameter(description = "队列id") @RequestParam("queueId") Long queueId,
                            @Parameter(description = "导入excel文件") @RequestParam("file") MultipartFile file) throws IOException {
        delayQueueMessageService.importExcel(queueId, file.getInputStream());
    }

    @GetMapping("/import/template")
    @SaCheckPermission("queue:delay_queue_message:import")
    @Operation(summary = "延迟队列消息表 excel导入模板")
    public void importTemplate() throws IOException {
        ServletUtil.download("延迟队列消息-导入模板.xlsx",
                outputStream -> delayQueueMessageService.importExcelTemplate(outputStream));
    }

    @GetMapping("/export/excel")
    @SaCheckPermission("queue:delay_queue_message:export")
    @Operation(summary = "延迟队列消息表 excel导出")
    public void exportExcel(@ParameterObject DelayQueueMessagePageParam param) throws IOException {
        ServletUtil.download("延迟队列消息-导出数据.xlsx",
                outputStream -> delayQueueMessageService.exportExcel(param, outputStream));
    }

}

